<?php

class ctrl_wish_wishProduct extends L {

    /**
     * 描述 ：wish产品统计页面展示
     * 作者 ：Zoro.Zhu
    **/
    public function index(){
        $this->view->_pagingHtml = $this->paging();
        $this->view->operType = model_com::getVsConfig('wishProductOperType');
        $this->view->accountList = model_com::getAccount('wish');
        $this->view->headTitle = 'wish产品统计';
        $this->display('/html/wish/wishProduct.html');
    }

    /**
     * 描述 : 获取分页
     * 作者 : Zoro.Zhu
     */
    public function &paging($params = array()){
        $sql = model_wishProduct::searchSql($params);
        $url = of::config('_of.rootUrl');
        $config = array(
            "<div><input type=\"checkbox\" name=\"checkAll\"></div>" => '<input type="checkbox" name="check[]"  value="{`id`}">',
            "<div align='center'>明细</div>" => "<input onclick='wishProductObj.unfoldDetail(\"{`id`}\")' type='button' style='font-size:14px;width: 30px;height: 30px' class=\"btn btn-primary btn-sm showDetailBtn\" id='detail_{`id`}' value='+' />",
            '图片' => '<div style="margin-right:0px;position: relative;width: 90px;height: 90px"><div class="{`_zuan`}"></div><img src="{`imgUrl`}" style="width: 90px;height: 90px;display:block;" /></div>',
            '产品ID<br>SPU<br>wish账号名称' => '<a href="' . $url . '/?c=ctrl_wish_wishProduct&a=productChart&id={`id`}" target="_blank">{`id`}</a><br>{`parentSku`}<br>{`account`}',
            '上传时间' => array(
                '_attr' => array(
                    'body' => '{`uploadTime`}',
                    'sort' => 'uploadTime'
                )
            ),
            '更新时间' => array(
                '_attr' => array(
                    'body' => '{`updTime`}',
                    'sort' => 'updTime'
                )
            ),
            '收藏' => array(
                '_attr' => array(
                    'body' => '{`numberSaves`}',
                    'sort' => 'numberSaves'
                )
            ),
            '售出' => array(
                '_attr' => array(
                    'body' => '{`numberSold`}',
                    'sort' => 'numberSold'
                )
            ),
            '产品状态<br>加钻<br>删除' => '{`reviewStatus`}<br>{`isPromoted`}<br>{`removedByMerchant`}',
            'SKU及价格明细' => '{`_skuDetail`}',
            '总曝光量' => array(
                '_attr' => array(
                    'body' => '{`totalFeedImpressions`}',
                    'sort' => 'totalFeedImpressions'
                )
            ),
            '总浏览量<br>曝光浏览比' => array(
                '_attr' => array(
                    'body' => '{`totalImpressions`}<br>{`browse`}',
                    'sort' => 'totalImpressions'
                )
            ),
            '购物车<br>浏览加车比' => array(
                '_attr' => array(
                    'body' => '{`add_to_cart`}<br>{`bicycleRatio`}',
                    'sort' => 'add_to_cart'
                )
            ),
            '总评分' => array(
                '_attr' => array(
                    'body' => '{`sum_ratings`}',
                    'sort' => 'sum_ratings'
                )
            ),
            '总评论' => array(
                '_attr' => array(
                    'body' => '{`total_ratings`}',
                    'sort' => 'total_ratings'
                )
            ),
            '总退款' => array(
                '_attr' => array(
                    'body' => '{`totalRefund`}',
                    'sort' => 'totalRefund'
                )
            ),
            '操作' => '<div class="btn-group">
                        <button type="button" class="btn btn-primary btn-sm dropdown-toggle dropdownMenu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                            操作 <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu pull-right context-menu dropDownCur" role="menu" style="margin-top: 0px">
                        <li><a href="javascript:wishProductObj.loadData(\'{`id`}\',\'{`account`}\')">更新</a></li>
                        <li><a href="javascript:wishProductObj.addProductLog(\'{`id`}\')">添加日志</a></li>
                        <li><a href="javascript:wishProductObj.updateProductPrice(\'{`id`}\',\'{`account`}\')">修改售价</a></li>
                        <li><a href="javascript:wishProductObj.updateFee(\'{`id`}\',\'{`account`}\')">修改运费</a></li>
                        <li><a href="' . $url . '/?c=ctrl_wish_wishProduct&a=lookKeywordView&id={`id`}&account={`account`}"  target="_blank">优化关键词</a></li>
                        <li><a href="javascript:wishProductObj.autoUpdatePrice(\'{`id`}\',\'{`account`}\')">自动调价</a></li>
                        </ul>
                        </div>',
            '_attr' => array(
                "attr" => array (
                    "table" => 'id=wishProductList class="table table-hover table-condensed table-striped table-scroll jsHoverDetails textC"',
                    "btr" => "align='center' class='of-paging_item_odd tr_{`id`}'",
                ),
                'data' => &$sql,
                'params' => &$params,
                'call' => array($this, 'asCall'),
                'method' => __METHOD__,
                'save' => 'auto',
                'empty' => '查无此数据'
            )
        );
        return $this->_com->paging($config);
    }

    /**
     * 描述 : 整理数据
     * 作者 : Zoro.Zhu
     */
    public function asCall(&$data){
        foreach($data['data'] as &$val){
            $proInfo = json_decode($val['data'], true);
            $val['imgUrl'] = $proInfo['image'];
            $val['_skuDetail'] = "<table>";
            foreach($proInfo['detail'] as $key => $row){
                $style = $key > 1 ? 'display: none;' : '';
                $class = $key > 1 ? "skuDetail_{$val['id']}" : '';
                $val['_skuDetail'] .= "<tr class='{$class}' style='{$style}'>
                    <td width='180px'>{$row['sku']}</td>
                    <td width='100px'>{$row['size']}</td>
                    <td width='100px'>售价{$row['localizedPrice']}</span></td>
                    <td width='100px'>运费{$row['localizedShipping']}</td>
                </tr>";
            }
            $key > 1 && $val['_skuDetail'] .= "<tr><td colspan='4' id='expand_{$val['id']}'><a onclick=\"wishProductObj.skuDetail('{$val['id']}')\">展开</a></td></tr>";
            $val['_skuDetail'] .= "</table>";
            $val['_zuan'] = empty($val['isPromoted']) ? '' : 'sell-hot-iocn';
            $val['isPromoted'] = empty($val['isPromoted']) ? '否' : '是';
            $val['removedByMerchant'] = empty($val['removedByMerchant']) ? '否' : '是';
            $val['uploadTime'] = substr($val['uploadTime'], 0, 10);
            !empty($val['total_ratings']) && $val['sum_ratings'] = round($val['sum_ratings'] / $val['total_ratings'], 2);
            $val['browse'] = !empty($val['totalFeedImpressions']) && !empty($val['totalImpressions']) ? round($val['totalFeedImpressions'] / $val['totalImpressions']) . ':1' : '-';
            $val['bicycleRatio'] = !empty($val['add_to_cart']) && !empty($val['totalImpressions']) ? round($val['totalImpressions'] / $val['add_to_cart']) . ':1' : '-';
        }
    }

    /**
     * 描述 : 获取统计明细数据
     * 作者 : Zoro.Zhu
     */
    public function getDetail(){
        if(!empty($_POST['id'])){
            $data = L::sql("SELECT
                `date`, `feed_impression`, `impressions`, `wishes`, `num_sold`,
                `add_to_cart`, `daily_sum_ratings`, `refund_reasons_dict_count`, `refund_reasons_dict`,
                `total_m_txn_cost`, `total_m_txn_count`
            FROM
                wish_product_stats 
            WHERE
                `id` = '{$_POST['id']}'
            ORDER BY `date` DESC");
            return ['state' => 200, 'data' => $data, 'info' => '获取成功'];
        }
    }

    /**
     * 描述 : Wish产品统计图表
     * 作者 : Zoro.Zhu
     */
    public function productChart(){
        if(!empty($_GET['id'])){
            $chart = model_wishProduct::getWishProductChart($_GET);
            //根据时间搜索
            if (!empty($_GET['timeS']) || !empty($_GET['timeE'])) {
                echo json_encode(['code' => 200, 'info' => '加载成功', 'data' => json_encode($chart)]);
                exit;
            }
            $this->view->chart = json_encode($chart);
            $this->view->title = 'Wish产品统计图表';
            $this->view->val = $_GET['id'];
            $productInfo = model_wishProduct::getProductInfo($_GET['id']);
            $this->view->imgUrl = !empty($productInfo['image']) ? $productInfo['image'] : '';
            $this->view->_logs = model_wishProduct::getProductLog($_GET);
            $this->display('/html/wish/wishProductChart.html');
        }else{
            echo '错误!!';
        }
    }

    /**
     * 描述 : 添加操作日志页面
     * 作者 : Zoro.Zhu
     */
    public function addProductLogView(){
        if(!empty($_GET['id'])){
            $this->view->id = $_GET['id'];
            $this->display('/html/wish/wishProductAddLog.html');
        }else{
            echo '错误!!';
        }
    }

    /**
     * 描述 : 添加操作日志
     * 作者 : Zoro.Zhu
     */
    public function addProductLog(){
        if(!empty($_POST['id'])){
            L::sql("INSERT INTO `wish_product_log`(
              `date`, `productId`, `remark`
            ) VALUES (
              '{$_POST['date']}', '{$_POST['id']}', '{$_POST['remark']}'
            )");
            return ['state' => 200, 'info' => '添加成功'];
        } else {
            return ['state' => 301, 'info' => '异常'];
        }
    }

    /**
     * 描述 : 修改运费的页面
     * 作者 : Zoro.Zhu
     */
    public function updateFeeView(){
        if(!empty($_GET['id']) && !empty($_GET['account'])){
            $this->view->id = $_GET['id'];
            $this->view->account = $_GET['account'];
            $token = model_vsAccount::getAccountToken(['account' => $_GET['account']]);
            if(!empty($token['accessToken'])){
                $productData = serv_rapi_wish::getProductData(['id' => $_GET['id'], 'accessToken' => $token['accessToken']]);
                $shipping = $productData['data']['Product']['country_shippings'];
                if(!empty($shipping)){
                    $country = model_com::getCountryCode();
                    $feeData = [];
                    foreach ($shipping as $row){
                        $feeData[$row['CountryShipping']['country_code']] = $row['CountryShipping'] + $country[$row['CountryShipping']['country_code']];
                    }
                    $this->view->feeData = $feeData;
                    $this->display('/html/wish/updateFee.html');
                    exit;
                }
            }
            echo '请重试！！';
        }else{
            echo '错误！！';
        }
    }

    /**
     * 描述 : 修改运费
     * 作者 : Zoro.Zhu
     */
    public function updateFee(){
        if(!empty($_POST['id']) && !empty($_POST['account'])){
            $token = model_vsAccount::getAccountToken(['account' => $_POST['account']]);
            $res = serv_rapi_wish::updateShipping(['id' => $_POST['id'], 'accessToken' => $token['accessToken'], 'fee' => $_POST['fee']]);
            if($res){
                $remark = '修改运费：原来是' . $_POST['oldShippingFee'] . ',修改成' . current($_POST['fee']);
                L::sql(null);
                L::sql("INSERT INTO `wish_product_log`(
                  `date`, `productId`, `remark`
                ) VALUES (
                  '" . date('Y-m-d H:i:s') . "', '{$_POST['id']}', '{$remark}'
                )");
                $oper = L::sql("SELECT
                    oper 
                FROM
                    `wish_product` 
                WHERE
                    id = '{$_POST['id']}'");
                $data = !empty($oper[0]['oper']) ? json_decode($oper[0]['oper'], true) : [];
                $data['shipFee'] = 1;
                $json = addslashes(json_encode($data));
                L::sql("UPDATE `wish_product` 
                SET `oper` = '{$json}' 
                WHERE
                    `id` = '{$_POST['id']}'");
                L::sql(true);
                return ['state' => 200, 'info' => '修改成功'];
            } else {
                return ['state' => 300, 'info' => '修改失败'];
            }
        }
    }

    /**
     * 描述 : 修改售价页面
     * 作者 : Zoro.Zhu
     */
    public function updateProductPriceView(){
        if(!empty($_GET['id']) && !empty($_GET['account'])){
            $this->view->id = $_GET['id'];
            $this->view->account = $_GET['account'];
            $token = model_vsAccount::getAccountToken(['account' => $_GET['account']]);
            if(!empty($token['accessToken'])){
                $productData = serv_rapi_wish::getProductData(['id' => $_GET['id'], 'accessToken' => $token['accessToken']]);
                $skuInfo = $productData['data']['Product']['variants'];
                if(!empty($skuInfo)){
                    $this->view->skuInfo = $skuInfo;
                    $this->view->oldPriceInfo = json_encode($skuInfo);
                    $this->display('/html/wish/updateProductPrice.html');
                    exit;
                }
            }
            echo '请重试！！';
        }else{
            echo '错误！！';
        }
    }

    /**
     * 描述 : 自动修改价格页面
     * 作者 : Zoro.Zhu
     */
    public function autoUpdatePriceView(){
        if(!empty($_GET['id']) && !empty($_GET['account'])){
            $this->view->id = $_GET['id'];
            $this->view->account = $_GET['account'];
            $token = model_vsAccount::getAccountToken(['account' => $_GET['account']]);
            if(!empty($token['accessToken'])){
                $productData = serv_rapi_wish::getProductData(['id' => $_GET['id'], 'accessToken' => $token['accessToken']]);
                $skuInfo = $productData['data']['Product']['variants'];
                $config = L::sql("SELECT
                    configData 
                FROM
                    `wish_product_update_price` 
                WHERE
                    id = '{$_GET['id']}'");
                $configData = [];
                if(!empty($config[0]['configData'])){
                    $configData = json_decode($config[0]['configData'], true);
                    $oldPriceInfo = json_decode(stripslashes($configData['oldPriceInfo']), true);
                }
                if(!empty($skuInfo)){
                    $this->view->configData = $configData;
                    $this->view->shipping = $productData['data']['Product']['country_shippings'][0]['CountryShipping'];
                    $this->view->skuInfo = $skuInfo;
                    $this->view->oldPriceInfo = !empty($oldPriceInfo) ? json_encode($oldPriceInfo) : json_encode($skuInfo);
                    $this->display('/html/wish/autoUpdatePrice.html');
                    exit;
                }
            }
            echo '请重试！！';
        }else{
            echo '错误！！';
        }
    }

    /**
     * 描述 : 提交自动调价
     * 作者 : Zoro.Zhu
     */
    public function autoUpdatePrice(){
        if($_POST['type'] == 'submit'){
            $json = addslashes(json_encode($_POST));
            $sql = "INSERT INTO `wish_product_update_price`(
              `id`, `addTime`, `configData`, `execTime`
            ) VALUES (
              '{$_POST['id']}','" . date('Y-m-d H:i:s') . "', '{$json}', '2000-01-01 00:00:00'
            ) ON DUPLICATE KEY UPDATE
                `configData`=VALUES(`configData`),
                `execTime`=VALUES(`execTime`)";
            L::sql($sql);
            return ['state' => 200, 'info' => '提交成功'];
        } else {
            L::sql("DELETE 
            FROM
                `wish_product_update_price` 
            WHERE
                id = '{$_POST['id']}'");
            return ['state' => 200, 'info' => '取消成功'];
        }
    }

    /**
     * 描述 : 查看关键词页面
     * 作者 : Zoro.Zhu
     */
    public function lookKeywordView(){
        set_time_limit(0);
        if(!empty($_GET['id']) && !empty($_GET['account'])){
            $this->view->id = $_GET['id'];
            $this->view->account = $_GET['account'];
            $token = model_vsAccount::getAccountToken(['account' => $_GET['account']]);
            if(!empty($token['accessToken'])){
                $productData = serv_rapi_wish::getProductData(['id' => $_GET['id'], 'accessToken' => $token['accessToken']]);
                $tags = $productData['data']['Product']['tags'];
                $myInfo = $productData['data']['Product'];
                $dateUploaded = explode("-", $myInfo['date_uploaded']);
                $myInfo['date_uploaded'] = $dateUploaded[2] . '-' . $dateUploaded[0] . '-' . $dateUploaded[1];
                $this->view->myInfo = $myInfo;          //我方产品信息
                $tag = [];
                if(!empty($tags)){
                    //整理我方关键词信息
                    foreach($tags as $t){
                        $tt = strtolower($t['Tag']['name']);
                        $tag[$tt] = $tt;
                    }
                    $tagList = ctrl_wish_mq::getKeyword(['data' => ['keywords' => join(',', $tag), 'look' => true]]);
                    $this->view->tagList = $tagList;        //我方关键词信息
                    //匹配别人的产品信息
                    if(!empty($_GET['keyword'])){
                        $otheInfo = self::getTaosjItem(trim($_GET['keyword']), $_GET['id'], 2);
                    } else {
                        $otheInfo = self::getTaosjItem($myInfo['name'], $_GET['id']);
                    }
                    if(!empty($otheInfo['itemId'])){
                        $otheInfo2 = serv_rep_taomaiwang::getItemInfo($otheInfo['itemId'], $otheInfo['merchantId']);
                        $otheInfo += $otheInfo2;
                        $otheInfo['itemDesc'] = str_replace("<br>", "\n", $otheInfo['itemDesc']);
                        $this->view->otheInfo = $otheInfo;          //别人的产品信息

                        //别人关键词信息
                        $otheTag = explode('^', $otheInfo['wishTag']);
                        $oTag = [];
                        foreach($otheTag as $r){
                            $tt = strtolower(trim($r, '@'));
                            $oTag[$tt] = $tt;
                        }
                        $oTagList = ctrl_wish_mq::getKeyword(['data' => ['keywords' => join(',', $oTag), 'look' => true]]);
                        $this->view->oTagList = $oTagList;        //别人关键词信息

                        //别人的PB关键词信息
                        $pbTag = serv_rep_taomaiwang::getItemPbInfo($otheInfo['itemId'], $otheInfo['merchantId']);
                        if(!empty($pbTag['contents'])){
                            $otheTag = explode('^', $pbTag['contents']);
                            $pbTags = [];
                            foreach($otheTag as $r){
                                $tt = strtolower(trim($r, '@'));
                                $pbTags[$tt] = $tt;
                            }
                            $pbTagList = ctrl_wish_mq::getKeyword(['data' => ['keywords' => join(',', $pbTags), 'look' => true]]);
                            $this->view->pbTagList = $pbTagList;        //别人PB关键词信息
                        }
                    }
                    $this->view->clevel = model_com::getVsConfig("competitionReachLevel");
                    $this->display('/html/wish/lookProductView.html');
                    exit;
                }
            }
            echo '请重试！！';
        }else{
            echo '错误！！';
        }
    }

    /**
     * 描述 : 获取数据递归
     * 作者 : Zoro.Zhu
     */
    public static function getTaosjItem($name, $id = '', $coefficient = 0.5){
        if($coefficient < 1){
            $keyWords = explode(' ', $name);
            $keyWord = [];
            foreach($keyWords as $k){
                if(!preg_match('/\d+/',$k) && strlen($k) > 3){
                    $keyWord[] = $k;
                }
            }
            $count = count($keyWord);
            $count = ceil($count * $coefficient);
            $keyWords = "";
            for($i = 0; $i < $count; $i++){
                $keyWords .= $keyWord[$i] . ' ';
            }
        } else {
            $keyWords = $name;
        }
        $otheInfo = serv_rep_taomaiwang::getItem($keyWords);
        if(!empty($otheInfo[0]['itemId']) && $otheInfo[0]['itemId'] != $id){
            return $otheInfo[0];
        }
        if(!empty($otheInfo[1]['itemId']) && $otheInfo[1]['itemId'] != $id){
            return $otheInfo[1];
        }
        if($coefficient > 0.01 && $coefficient < 1){
            return self::getTaosjItem($name, $id, $coefficient - 0.1);
        } else {
            return [];
        }
    }

    /**
     * 描述 : 查看关键词热度
     * 作者 : Zoro.Zhu
     */
    public function lookKeyword(){
        set_time_limit(0);
        if(!empty($_GET['k'])){
            $_GET['k'] = trim($_GET['k']);
            if(strlen($_GET['k']) == 24){
                $pbTag = serv_rep_taomaiwang::getItemPbInfo($_GET['k']);
                if(!empty($pbTag['contents'])){
                    $otheTag = explode('^', $pbTag['contents']);
                    $pbTags = [];
                    foreach($otheTag as $r){
                        $tt = strtolower(trim($r, '@'));
                        $pbTags[$tt] = $tt;
                    }
                    $_GET['k'] = join(',', $pbTags);
                }
            }
            $tagList = ctrl_wish_mq::getKeyword(['data' => ['keywords' => $_GET['k'], 'look' => true]]);
            $this->view->tagList = $tagList;
        }
        $this->view->clevel = model_com::getVsConfig("competitionReachLevel");
        $this->display('/html/wish/lookKeywordView.html');
    }

    /**
     * 描述 : 修改售价
     * 作者 : Zoro.Zhu
     */
    public function updateProductPrice(){
        if(!empty($_POST['id']) && !empty($_POST['account'])){
            $token = model_vsAccount::getAccountToken(['account' => $_POST['account']]);
            $oldPriceInfo = json_decode(stripslashes($_POST['oldPriceInfo']), true);
            $remark = '';
            $remark2 = '';
            foreach($oldPriceInfo as $row){
                $errorMsg = $remarks = $remarks2 = '';
                $sku = $row['Variant']['sku'];
                if($row['Variant']['msrp'] - $_POST['msrp'][$sku] != 0 || $row['Variant']['localized_price'] - $_POST['price'][$sku] != 0){
                    $data = [];
                    if($row['Variant']['localized_price'] - $_POST['price'][$sku] != 0){
                        $data['localized_price'] = $_POST['price'][$sku];
                        $data['localized_currency_code'] = 'CNY';
                        $remarks = "SKU:{$sku}修改金额，从{$row['Variant']['localized_price']}修改为{$_POST['price'][$sku]}。<br>";
                    }
                    if($row['Variant']['msrp'] - $_POST['msrp'][$sku] != 0){
                        $data['msrp'] = $_POST['msrp'][$sku];
                        $remarks2 = "SKU:{$sku}修改MSRP，从{$row['Variant']['msrp']}修改为{$_POST['msrp'][$sku]}。<br>";
                    }
                    $res = serv_rapi_wish::updateSkuInfo(['sku' => $sku, 'access_token' => $token['accessToken']] + $data);
                    if($res === true){
                        $remark .= $remarks;
                        $remark2 .= $remarks2;
                    }elseif ($res === false){
                        $errorMsg .= "{$sku}执行失败，请重试！<br>";
                    }else{
                        $errorMsg .= "{$sku} : {$res} <br>";
                    }
                }
            }
            if(empty($errorMsg)){
                $remark = $remark . $remark2;
                L::sql(null);
                L::sql("INSERT INTO `wish_product_log`(
                  `date`, `productId`, `remark`
                ) VALUES (
                  '" . date('Y-m-d H:i:s') . "', '{$_POST['id']}', '{$remark}'
                )");
                $oper = L::sql("SELECT
                    oper 
                FROM
                    `wish_product` 
                WHERE
                    id = '{$_POST['id']}'");
                $data = !empty($oper[0]['oper']) ? json_decode($oper[0]['oper'], true) : [];
                $data['price'] = 1;
                $json = addslashes(json_encode($data));
                L::sql("UPDATE `wish_product` 
                SET `oper` = '{$json}' 
                WHERE
                    `id` = '{$_POST['id']}'");
                L::sql(true);
                return ['state' => 200, 'info' => '修改成功'];
            } elseif((!empty($remark) || !empty($remark2)) && !empty($errorMsg)) {
                $remark = $remark . $remark2;
                L::sql(null);
                L::sql("INSERT INTO `wish_product_log`(
                  `date`, `productId`, `remark`
                ) VALUES (
                  '" . date('Y-m-d H:i:s') . "', '{$_POST['id']}', '{$remark}'
                )");
                $oper = L::sql("SELECT
                    oper 
                FROM
                    `wish_product` 
                WHERE
                    id = '{$_POST['id']}'");
                $data = !empty($oper[0]['oper']) ? json_decode($oper[0]['oper'], true) : [];
                $data['price'] = 1;
                $json = addslashes(json_encode($data));
                L::sql("UPDATE `wish_product` 
                SET `oper` = '{$json}' 
                WHERE
                    `id` = '{$_POST['id']}'");
                L::sql(true);
                return ['state' => 300, 'info' => '部分修改成功，错误信息：' . $errorMsg];
            } else {
                return ['state' => 301, 'info' => '修改失败，错误信息：' . $errorMsg];
            }
        }
    }

    /**
     * 描述 : 修改关键词
     * 作者 : Zoro.Zhu
     */
    public function updateKeyword(){
        if(!empty($_POST['id']) && !empty($_POST['account'])){
            $token = model_vsAccount::getAccountToken(['account' => $_POST['account']]);
            $tag = join(",", $_POST['keywords']);
            $res = serv_rapi_wish::productUpdate(['id' => $_POST['id'], 'access_token' => $token['accessToken'], 'tags' => $tag]);
            if($res === true){
                $remark = '修改关键词：修改成' . addslashes($tag);
                L::sql(null);
                L::sql("INSERT INTO `wish_product_log`(
                  `date`, `productId`, `remark`
                ) VALUES (
                  '" . date('Y-m-d H:i:s') . "', '{$_POST['id']}', '{$remark}'
                )");
                $oper = L::sql("SELECT
                    oper 
                FROM
                    `wish_product` 
                WHERE
                    id = '{$_POST['id']}'");
                $data = !empty($oper[0]['oper']) ? json_decode($oper[0]['oper'], true) : [];
                $data['keyword'] = 1;
                $json = addslashes(json_encode($data));
                L::sql("UPDATE `wish_product` 
                SET `oper` = '{$json}' 
                WHERE
                    `id` = '{$_POST['id']}'");
                L::sql(true);
                return ['state' => 200, 'info' => '修改成功'];
            } else {
                return ['state' => 300, 'info' => !empty($res) ? $res : '修改失败'];
            }
        }
    }

    /**
     * 描述 : 修改标题
     * 作者 : Zoro.Zhu
     */
    public function updateTitle(){
        if(!empty($_POST['id']) && !empty($_POST['account'])){
            $token = model_vsAccount::getAccountToken(['account' => $_POST['account']]);
            $res = serv_rapi_wish::productUpdate(['id' => $_POST['id'], 'access_token' => $token['accessToken'], 'name' => $_POST['title']]);
            if($res === true){
                $remark = '修改标题：修改成' . addslashes($_POST['title']);
                L::sql(null);
                L::sql("INSERT INTO `wish_product_log`(
                  `date`, `productId`, `remark`
                ) VALUES (
                  '" . date('Y-m-d H:i:s') . "', '{$_POST['id']}', '{$remark}'
                )");
                $oper = L::sql("SELECT
                    oper 
                FROM
                    `wish_product` 
                WHERE
                    id = '{$_POST['id']}'");
                $data = !empty($oper[0]['oper']) ? json_decode($oper[0]['oper'], true) : [];
                $data['keyword'] = 1;
                $json = addslashes(json_encode($data));
                L::sql("UPDATE `wish_product` 
                SET `oper` = '{$json}' 
                WHERE
                    `id` = '{$_POST['id']}'");
                L::sql(true);
                return ['state' => 200, 'info' => '修改成功'];
            } else {
                return ['state' => 300, 'info' => !empty($res) ? $res : '修改失败'];
            }
        }
    }

    /**
     * 描述 : 获取关键词数据
     * 作者 : Zoro.Zhu
     */
    public function getKeywordInfo(){
        $keyword = !empty($_POST['keyword']) ? strtolower($_POST['keyword']) : 'test';
        $sign = !empty($_POST['sign']) ? $_POST['sign'] : '431039.159886';
        $_POST['translator'] = 'bing';
        $data = [];
        $tk = serv_rep_baidu::googleTk($keyword);
        $temp = serv_rep_baidu::translates($keyword, $_POST['translator'], 'en', $sign, $tk);
        if (substr($temp, 0, 3) == pack("CCC", 0xEF, 0xBB, 0xBF)) {
            $temp = substr($temp, 3);
        }
        $temp = preg_replace('/(^"*)|("$)/i', '', $temp);
        $data['en'] = !empty($temp) ? strtolower($temp) : $keyword;
        $temp = serv_rep_baidu::translates($keyword, $_POST['translator'], 'cn', $sign, $tk);
        if (substr($temp, 0, 3) == pack("CCC", 0xEF, 0xBB, 0xBF)) {
            $temp = substr($temp, 3);
        }
        $temp = preg_replace('/(^"*)|("$)/i', '', $temp);
        $data['cn'] = $temp;
        $tagList = ctrl_wish_mq::getKeyword(['data' => ['keywords' => $data['en'], 'look' => true]]);
        !empty($tagList[$data['en']]) && $data += $tagList[$data['en']];
        return ['state' => 200, 'data' => $data, 'info' => '获取成功'];
    }

    public function test(){
        $otheInfo2 = serv_rep_taomaiwang::getItem('Wallet Money Pockets', 2, 0);
        p($otheInfo2);
    }

}
return true;